package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 简易记事本
 */
public class Test2 {
    public static void main(String[] args) throws IOException {
        /*FileOutputStream fos = new FileOutputStream("./demo.txt");
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输入：");
            String line = scanner.nextLine();
            if("exit".equalsIgnoreCase(line)){
                break;
            }else{
                byte[] data = line.getBytes(StandardCharsets.UTF_8);
                fos.write(data);
            }
        }
        fos.close();
        System.out.println("写入完毕");*/
        FileOutputStream fos = new FileOutputStream("./demo.txt");
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输入：");
            String line = scanner.nextLine();
            if("exit".equalsIgnoreCase(line)){
                break;

            }
            byte[] data = line.getBytes(StandardCharsets.UTF_8);
            fos.write(data);
        }

        System.out.println("写入文件完毕");
    }
}
